<template>
    <Modal
        :value="editModalStatus"
        title="添加/编辑"
        @on-ok="ok"
        @on-cancel="cancel">
        <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
            <FormItem label="维修类型" prop="resourceName">
                <Input v-model="formValidate.type_name" placeholder="请输入维修项目类型名称"></Input>
            </FormItem>

            <FormItem label="状态" prop="status">
                <RadioGroup v-model="formValidate.status">
                    <Radio label="1">启用</Radio>
                    <Radio label="2">禁用</Radio>
                </RadioGroup>
            </FormItem>
        </Form>
    </Modal>
</template>
<script>
    import API from '../../config/api'
    import qs from 'qs'
    export default {
        props: ['editModalStatus','editData','flag'],
        data () {
            return {
                formValidate:{
                    id:'',
                    type_name:'',
                    add_time:'',
                    status:'1',

                },
                ruleValidate: {
                    type_name: [
                        { required: true, message: '菜单名不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            ok () {
                this.axios.post(API.POST_PROJECTTYPE_SAVE, qs.stringify(this.formValidate)).then(response => {
                    if (response.data.code === 1) {
                        this.$emit('shuaxin');
                        this.$Message.success(response.data.msg);
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                    this.cancel();
                }, response => {
                    this.$Message.error('网络异常!');
                })
            },
            cancel () {
                this.$emit('closeModal');
            }
        },
        watch:{
            flag(val){
                console.log(this.flag)
                if(val==0){
                   /* for(let key in this.formValidate){
                        this.formValidate[key] = val[key];
                    }*/
                    this.formValidate=this.editData;
                }else {
                    this.formValidate = {
                        id:'',
                        type_name:'',
                        add_time:'',
                        status:'1',
                    };
                }
            }
        }
    }
</script>
